#coding=utf-8
import os
from selenium import webdriver
import time

dir = os.path.dirname(os.path.abspath('.'))
chrome_driver_path = dir + '/tools/chromedriver.exe'
driver = webdriver.Chrome(chrome_driver_path)
driver.get('https://www.baidu.com')
time.sleep(2)
#获取百度搜索窗口句柄
search_windows = driver.current_window_handle

driver.find_element_by_link_text('登录').click()
time.sleep(3)
driver.find_element_by_link_text('立即注册').click()
time.sleep(2)
#获得当前所有打开的窗口的句柄
all_handles = driver.window_handles
time.sleep(2)
#进入注册窗口
for handle in all_handles:
    print(handle)
    if handle == search_windows:
        driver.switch_to_window(handle)
        print('SEARCH windows')
        #driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_3__userName']").send_keys('username')
        #driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_3__password']").send_keys('password')
        time.sleep(2)